package com.yonyou.cyxdms.sysAuth.service.service.message;

import com.yonyou.cloud.http.plus.domain.MessEvent;
import com.yonyou.cloud.http.plus.remote.IRemoteInvoke;
import com.yonyou.cyx.framework.util.bean.ApplicationContextHelper;
import com.yonyou.cyxdms.framework.bean.dto.user_info.LoginInfoDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author renwd
 * @since 2019-10-17
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ProducerMsgServiceImpl implements ProducerMsgService {

    @Autowired
    private IRemoteInvoke iRemoteInvoke;

    /**
     *  NOTIFY发送请求
     *
     * @param
     * @return String
     * @author maxingjian
     * @since 2019/11/08
     */
    @Override
    public String sendMsgForParam(String ownerCode,String ownerParCode, String companyCode)
    {
        LoginInfoDto login = ApplicationContextHelper.getBeanByType(LoginInfoDto.class);
        Map<String,Object> data=new HashMap<>();
        data.put("appId", login.getAppId());
        data.put("ownerCode", ownerCode);
        data.put("ownerParCode", ownerParCode);
        data.put("companyCode", companyCode);
        data.put("orgId", login.getOrgId());
        //远程调用对象：url / body参数（json）/  header
        MessEvent messEvent = new MessEvent();
        String channel ="sysParam";
        messEvent.setUrl("http://OPS-NOTIFY/notify/invoke/message?channel="+channel);
        messEvent.setParam(data);
        messEvent.setHeaders(null);
        //远程调用
        iRemoteInvoke.sendPostWithTransaction(messEvent);
        return "success";
    }


}
